var pageSize = 10;
var pageNum = 1;
var page;
var list;
var layer;
var index;

$(function () {
    $("#menuId").val(sessionStorage.menuId);
    layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
    });
    setTimeout(function () {
        findPartnerList();
    }, 200);
});

//查询代理商列表
function findPartnerList() {
    var menuId = $("#menuId").val();

    var params = {
        "type": "query",
        "menuId": menuId,
        "pageSize": pageSize,
        "pageNum": pageNum
    };
    $.ajax({
        type: "post",
        url: "/partner/list",
        data: params,
        dataType: "json",
        success: function (data) {
            if (data.code == 1 && data.code != undefined) {
                list = data.list;
                page = data.page;
                var html = "";
                for (var l in list) {
                    html += '<tr><td>' + list[l].id + '</td>' +
                        '<td>' + list[l].nickName + '</td>'+
                        '<td>'+(list[l].phone == null ? "" : list[l].phone)+'</td>'+
                        '<td></td>'+
                        '<td>'+new Date(list[l].createTime).toLocaleString()+'</td>'+
                        '<td><button class="layui-btn layui-btn-normal" onclick="findDetails(' + list[l].id + ')">查看详情</button></td></tr>';
                }
                $("#partnerList").html(html);
                $("#total").html("共有数据：" + page.total + " 条");
                laypage({
                    cont: 'page'
                    , pages: page.pages
                    , first: 1
                    , curr: pageNum
                    , last: page.pages
                    , prev: '<em><</em>'
                    , next: '<em>></em>'
                    , jump: function (obj, first) {
                        pageNum = obj.curr;
                        if (!first) {
                            findPartnerList();
                        }
                    }
                });
            } else if (data == 9999 && data != undefined) {
                window.location.href = "/login_toLogin";
            } else if (data == 1111 && data != undefined) {
                alert("无权操作");
            }
        }
    });
}

//查看详情
function findDetails(id) {
    sessionStorage.inviterId = id;
    layer.open({
        title: ['邀请用户列表','color: #2299ee;border-bottom: 1px solid;']
        ,type: 2
        ,content: 'partnerDetails.html'
        ,area: ['100%', '100%']
        ,maxmin:true
    });
}
